<template>
  <div>
    <!-- 模糊搜索 -->
    <el-card class="searchTop">
      <div slot="header" style="font-size:16px;">条件查询</div>
        <el-form ref="form" :model="searchObj" label-width="100px">
          <el-row type="flex">
            <el-col :span="6">
              <el-form-item label="订单编号" prop="orderSn">
                <el-input size="mini" v-model="searchObj.orderSn" placeholder="请填写订单编号"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="退单状态" prop="status">
                <el-select size="mini" v-model="searchObj.status" placeholder="退单状态">
                  <el-option label="待处理" value="0"></el-option>
                  <el-option label="退货中" value="1"></el-option>
                  <el-option label="已完成" value="2"></el-option>
                  <el-option label="已拒绝" value="3"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
        </el-row>
        <el-row style="margin-left: 75%;">
          <el-form-item>
            <el-button size="mini" type="primary" @click="submitForm('form')">搜索</el-button>
            <el-button size="mini" @click="resetForm('form')">重置</el-button>
          </el-form-item>
        </el-row>
      </el-form>
    </el-card>

    <!-- 退单商品列表 -->
    <el-card class="searchTop">
        <el-table
          :data="list"
          border
          style="width: 100%">
          <el-table-column
            fixed
            type="index"
            align="center"
            label="#"
            width="50">
          </el-table-column>

          <el-table-column
            prop="orderSn"
            label="订单编号"
            align="center"
            width="300">
          </el-table-column>

          <el-table-column
            label="退单状态"
            align="center"
            width="200">
            <template slot-scope="scope">
              <div v-if="scope.row.status==0" class="dcl">待处理</div>
              <div v-if="scope.row.status==1" class="thz">退货中</div>
              <div v-if="scope.row.status==2" class="ywc">已完成</div>
              <div v-if="scope.row.status==3" class="yjj">已拒绝</div>
            </template>
          </el-table-column>

          <el-table-column
            prop="description"
            align="center"
            label="描述"
            width="200">
          </el-table-column>

          <el-table-column
            prop="reason"
            align="center"
            label="退单原因"
            width="200">
          </el-table-column>

          <el-table-column
            prop="productName"
            align="center"
            label="商品名称"
            width="150">
          </el-table-column>

          <el-table-column
            label="商品属性"
            align="center"
            width="200">
            <template slot-scope="scope">
              <div v-for="(item,index) in scope.row.productAttr" :key="index">{{item.key}}:{{item.value}}</div>
            </template>
          </el-table-column>

          <el-table-column
            prop="handleNote"
            align="center"
            label="商品备注"
            width="120">
          </el-table-column>

          <el-table-column
            prop="createTime"
            align="center"
            label="添加时间"
            width="300">
          </el-table-column>
          

          <el-table-column
            fixed="right"
            label="操作"
            align="center"
            width="150">
            <template slot-scope="scope">
              <el-button icon="el-icon-view" @click="checkRefund(scope.row.id)" type="primary" size="small">查看订单</el-button>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页器 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page.currentPage"
        :page-sizes="page.pageSizes"
        :page-size="page.size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="page.total">
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
import {findReturnApply} from '@/api/order/quitList';
import mixin from '@/mixins/index';
export default {
  mixins:[mixin],
  data(){
    return{
      //退单列表数据
      list:[],
      //模糊查询
      searchObj:{},
    }
  },
  created(){
    this.getData()
  },
  methods:{
    //获取退单列表
    getData(){
      findReturnApply(this.page.currentPage,this.page.size,this.searchObj).then(res=>{
        console.log(res);
        res.data.rows.forEach(res => {
          res.productAttr = JSON.parse(res.productAttr)
        });
        this.list = res.data.rows
        this.page.total = res.data.total
      })
    },
    //模糊搜索查询
    submitForm(formName){
      this.page.currentPage = 1
      this.getData()
    },
    //重置模糊搜素
    resetForm(formName){
      this.$refs[formName].resetFields();
    },
    //每页条数
    handleSizeChange(val){
      this.page.size = val
      this.page.currentPage = 1
      this.getData()
    },
    //当前页数
    handleCurrentChange(val){
      this.page.currentPage = val
      this.getData()
    },
    //查看退单详情跳转
    checkRefund(val){
      this.$router.push({name:'CheckRefund',query:{id:val}})
    }
  }
}
</script>

<style lang="scss" scoped>
.dcl,.thz,.ywc,.yjj{
  width: 58px;
  height: 30px;
  padding: 0 10px;
  line-height: 30px;
  font-size: 12px;
  border-width: 1px;
  border-style: solid;
  border-radius: 4px;
  margin: 0 auto;
}
.dcl{
  background-color: #f56c6c;
  border-color: #f56c6c;
  color: #fff;
}
.thz{
  background-color: #e6a23c;
  border-color: #e6a23c;
  color: #fff;
}
.ywc{
  background-color: #ecf5ff;
  border-color: #d9ecff;
  color: #409eff;
}
.yjj{
  background-color: #f4f4f5;
  border-color: #e9e9eb;
  color: #909399;
}
</style>